package com.example.extendanimationdemo;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class ExpandAnimation1 extends Animation {
	private View view;
	private LinearLayout.LayoutParams parmas;
	private int measuredHeight;
	private int willVisibility;

	public ExpandAnimation1(View view, int willVisibility) {
		super();
		this.view = view;
		this.willVisibility = willVisibility;
		this.view.setVisibility(0);
		((View) view.getParent()).measure(0, 0);
		measuredHeight = view.getMeasuredHeight();
		System.out.println("measuredHeight:" + measuredHeight);
		parmas = (LayoutParams) this.view.getLayoutParams();
	}

	public ExpandAnimation1(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected void applyTransformation(float interpolatedTime, Transformation t) {
		// TODO Auto-generated method stub
		super.applyTransformation(interpolatedTime, t);
		if (this.willVisibility == View.GONE) {
			// 0 1
			// 0 -measuredHeight;
			parmas.bottomMargin = (int) (-interpolatedTime * measuredHeight);
			this.view.requestLayout();
			System.out.println("hide=parmas.bottomMargin:" + parmas.bottomMargin);
		} else if (this.willVisibility == View.VISIBLE) {
			// 0 1
			// -measuredHeight 0
			parmas.bottomMargin = (int) (-measuredHeight + measuredHeight * interpolatedTime);
			System.out.println("show=parmas.bottomMargin:" + parmas.bottomMargin);
			this.view.requestLayout();
		}
		if (interpolatedTime == 1.0) {
			if (this.willVisibility == View.GONE) {
				this.view.setVisibility(8);
			}
		}
		//
	}
}
